<?php

namespace App\Service;

use App\Support\Response;
use Hyperf\Di\Annotation\Inject;

abstract class BaseService
{


    /**
     * @Inject()
     * @var Response
     */
    protected $response;


    /**
     * @param array $array
     * @param string $key
     * @param null $default
     * @return mixed
     */
    protected function arrayGet($array, $key, $default = null)
    {
        if (is_null($key)) {
            return $array;
        }

        if (isset($array[$key])) {
            return $array[$key];
        }

        foreach (explode('.', $key) as $segment) {
            if (! is_array($array) || ! array_key_exists($segment, $array)) {
                return value($default);
            }

            $array = $array[$segment];
        }
        return $array;
    }
}
